export const sortCount = (array: number[]) => {
  let maxV = array[0];
  
  array.forEach(item => {
    if (item > maxV) {
      maxV = item;
    }
  });

  let result: number[] = new Array(maxV + 1);
  let resultArr: number[] = [];

  for (let i = 0; i < array.length; i++) {
    if (!result[array[i]]) {
      result[array[i]] =  0;
    }
    result[array[i]]++;
  }
  
  result.forEach((item, index) => {
    if (item > 0) {
      for (let i = 0; i < item; i++) {
        resultArr.push(index);
      }
    }
  });

  return resultArr;
};

export const sortCount2 = (array: number[]) => {
  let result: {
    [props: number]: number;
  } = {};
  let resultArr: number[] = [];

  for (let i = 0; i < array.length; i++) {
    if (!result[array[i]]) {
      result[array[i]] =  0;
    }
    result[array[i]]++;
  }
  
  Object.keys(result).forEach((item) => {
    for (let i = 0; i < result[item]; i++) {
      resultArr.push(Number(item));
    }
  });

  return resultArr;
};
